﻿using System;
using System.Drawing;
using System.Windows.Forms;
using Oscilloscope.Adjust;
using Oscilloscope.ChannelBuffer;
using Oscilloscope.Curve;
using Oscilloscope.Exception;
using Oscilloscope.Screen;
using Oscilloscope.Util;
using Oscilloscope;
using System.Threading;
using System.Diagnostics;
using System.Linq;
using System.Collections.Generic;
using Growatt.OSC.Util;
using System.IO;

namespace Oscilloscope.Channel
{
    // Token: 0x0200000E RID: 14
    internal class Channel : IChannel
    {
        // Token: 0x0600006D RID: 109 RVA: 0x00005090 File Offset: 0x00003290
        public Channel(int channelSN, IOscilloscopeScreen oscs)
        {
            if (oscs == null)
            {
                throw new ArgumentNullException("oscs");
            }
            this.channelSN = channelSN;
            this.oscs = oscs;
            this.startTime = 0.0;
            this.endTime = 0.0;
            this.timePerCellGrade = 0;
            this.canvasSize = new Rectangle(0, 0, 0, 0);
            this.valuePerCellGrade = 0;
            this.baseLineValue = 0.0;
            this.lineColor = Color.White;
            this.lineWidth = 1f;
            this.bitMask = ushort.MaxValue;
            this.dataBufferStartTime = 0.0;
            this.dataBufferValidCount = 0;
            this.dataBuffer = null;
            this.curveGenerator = CurveGeneratorFactory.CurveGenerator(this);
        }

        // Token: 0x0600006E RID: 110 RVA: 0x00005153 File Offset: 0x00003353
        public IOscilloscopeScreen GetOscilloscopeScreen()
        {
            return this.oscs;
        }

        // Token: 0x0600006F RID: 111 RVA: 0x0000515B File Offset: 0x0000335B
        public int GetChannelSN()
        {
            return this.channelSN;
        }

        // Token: 0x06000070 RID: 112 RVA: 0x00005164 File Offset: 0x00003364
        public void DrawCurve(Graphics g)
        {
            Oscilloscope.Curve.Curve[] curves = this.curveGenerator.GetCurves();
            if (curves == null || curves.Length == 0)
            {
                return;
            }
            Pen pen = new Pen(this.lineColor, this.lineWidth);
            for (int i = 0; i < curves.Length; i++)
            {
                if (curves[i] != null && curves[i].CurveSegments != null && curves[i].CurveSegmentCount >= 1 && curves[i].CurvePoints != null)
                {
                    for (int j = 0; j < curves[i].CurveSegmentCount; j++)
                    {
                        if (curves[i].CurveSegments[j].PointCount >= 2)
                        {
                            for (int k = 0; k < curves[i].CurveSegments[j].PointCount - 1; k++)
                            {
                                g.DrawLine(pen, curves[i].CurvePoints[curves[i].CurveSegments[j].StartIndex + k], curves[i].CurvePoints[curves[i].CurveSegments[j].StartIndex + k + 1]);
                            }
                        }
                    }
                }
            }
            pen.Dispose();
        }
        public void DrawVPosArrow(Graphics g, int canvasWidth, int canvasHeight, Font font)
        {
            CurveVerPosIndicator[] curveVerPosIndicators = this.curveGenerator.GetCurveVerPosIndicators();
            if (curveVerPosIndicators == null || curveVerPosIndicators.Length == 0)
            {
                return;
            }
            SolidBrush solidBrush = new SolidBrush(this.GetColor());
            float x = (float)(canvasWidth - 8);
            for (int i = 0; i < curveVerPosIndicators.Length; i++)
            {
                if (curveVerPosIndicators[i] != null)
                {
                    float num = curveVerPosIndicators[i].YLocInCanvas;

                    Cursor cursor;
                    if (num < 0f)
                    {
                        num = 6f;
                        cursor = Cursors.PanNorth;
                    }
                    else if (num > (float)canvasHeight)
                    {
                        num = (float)(canvasHeight - 6);
                        cursor = Cursors.PanSouth;
                    }
                    else
                    {
                        cursor = Cursors.PanEast;
                    }
                    InternalUtils.DrawArrow(g, new RectangleF(x, num - 4f, 8f, 8f), cursor, solidBrush);
                    g.DrawString(curveVerPosIndicators[i].Text, font, solidBrush, 0f, num - 6f);
                }
            }
            solidBrush.Dispose();
        }
        // Token: 0x06000071 RID: 113 RVA: 0x00005290 File Offset: 0x00003490
  

        // Token: 0x06000072 RID: 114 RVA: 0x00005366 File Offset: 0x00003566
        public void SetTimeSpan(double startTime, double endTime)
        {
            if (startTime < 0.0 || endTime < 0.0 || startTime > endTime)
            {
                throw new ArgumentOutOfRangeException();
            }
            this.startTime = startTime;
            this.endTime = endTime;
        }

        // Token: 0x06000073 RID: 115 RVA: 0x00005398 File Offset: 0x00003598
        public void GetTimeSpan(out double startTime, out double endTime)
        {
            startTime = this.startTime;
            endTime = this.endTime;
        }

        // Token: 0x06000074 RID: 116 RVA: 0x000053AA File Offset: 0x000035AA
        public void SetTimePerCellGrade(int timePerCellGrade)
        {
            if (timePerCellGrade >= TimePerCellAdjustGrade.Instance.GradeCount)
            {
                throw new NotSupportGradeException();
            }
            this.timePerCellGrade = timePerCellGrade;
        }

        // Token: 0x06000075 RID: 117 RVA: 0x000053C6 File Offset: 0x000035C6
        public int GetTimePerCellGrade()
        {
            return this.timePerCellGrade;
        }

        // Token: 0x06000076 RID: 118 RVA: 0x000053CE File Offset: 0x000035CE
        public void SetCanvasSize(int width, int height)
        {
            if (width < 0 || height < 0)
            {
                throw new ArgumentOutOfRangeException();
            }
            this.canvasSize.Width = width;
            this.canvasSize.Height = height;
        }

        // Token: 0x06000077 RID: 119 RVA: 0x000053F6 File Offset: 0x000035F6
        public Rectangle GetCanvasSize()
        {
            return new Rectangle(0, 0, this.canvasSize.Width, this.canvasSize.Height);
        }

        // Token: 0x06000078 RID: 120 RVA: 0x00005418 File Offset: 0x00003618
        public void SetValuePerCellGrade(int valuePerCellGrade)
        {
            if (valuePerCellGrade >= ValuePerCellAdjustGrade.Instance.GradeCount)
            {
                throw new NotSupportGradeException();
            }

            float num = (float)((double)this.canvasSize.Height * (this.baseLineValue / (ValuePerCellAdjustGrade.Instance.GetValueOfGrade(this.valuePerCellGrade) * 8.0)));
            this.baseLineValue = (double)num * (ValuePerCellAdjustGrade.Instance.GetValueOfGrade(valuePerCellGrade) * 8.0 / (double)this.canvasSize.Height);
            this.valuePerCellGrade = valuePerCellGrade;
        }

        // Token: 0x06000079 RID: 121 RVA: 0x0000549A File Offset: 0x0000369A
        public int GetValuePerCellGrade()
        {


            return this.valuePerCellGrade;
        }

        // Token: 0x0600007A RID: 122 RVA: 0x000054A2 File Offset: 0x000036A2
        public void SetBaseLineValue(double value)
        {
            this.baseLineValue = value;
        }

        // Token: 0x0600007B RID: 123 RVA: 0x000054AB File Offset: 0x000036AB
        public double GetBaseLineValue()
        {
            return this.baseLineValue;
        }

        // Token: 0x0600007C RID: 124 RVA: 0x000054B4 File Offset: 0x000036B4
        public float GetBaseLinePos()
        {
            int height = this.GetCanvasSize().Height;
            float num = (float)height / 2f;
            return (float)((double)num - (double)height * (this.GetBaseLineValue() / (ValuePerCellAdjustGrade.Instance.GetValueOfGrade(this.GetValuePerCellGrade()) * 8.0)));
        }

        // Token: 0x0600007D RID: 125 RVA: 0x00005504 File Offset: 0x00003704
        public void MoveWaveUp(int movingTimes)
        {
            if (movingTimes < 0)
            {
                throw new ArgumentOutOfRangeException();
            }
            for (int i = 0; i < movingTimes; i++)
            {
                if (this.baseLineValue >= 0.0)
                {
                    if (InternalUtils.IsXbeDivByYwithNoRemainder(this.baseLineValue, ValuePerCellAdjustGrade.Instance.GetStepOfGrade(this.valuePerCellGrade)))
                    {
                        this.baseLineValue += ValuePerCellAdjustGrade.Instance.GetStepOfGrade(this.valuePerCellGrade);
                    }
                    else
                    {
                        this.baseLineValue = InternalUtils.GetIntegralMultipleOfStepBaseValueOf(this.baseLineValue, ValuePerCellAdjustGrade.Instance.GetStepOfGrade(this.valuePerCellGrade), true);
                    }
                }
                else if (InternalUtils.IsXbeDivByYwithNoRemainder(this.baseLineValue, ValuePerCellAdjustGrade.Instance.GetStepOfGrade(this.valuePerCellGrade)))
                {
                    this.baseLineValue += ValuePerCellAdjustGrade.Instance.GetStepOfGrade(this.valuePerCellGrade);
                }
                else
                {
                    this.baseLineValue = 0.0 - InternalUtils.GetIntegralMultipleOfStepBaseValueOf(Math.Abs(this.baseLineValue), ValuePerCellAdjustGrade.Instance.GetStepOfGrade(this.valuePerCellGrade), false);
                }
            }
        }

        // Token: 0x0600007E RID: 126 RVA: 0x00005610 File Offset: 0x00003810
        public void MoveWaveDown(int movingTimes)
        {
            if (movingTimes < 0)
            {
                throw new ArgumentOutOfRangeException();
            }
            for (int i = 0; i < movingTimes; i++)
            {
                if (this.baseLineValue >= 0.0)
                {
                    if (InternalUtils.IsXbeDivByYwithNoRemainder(this.baseLineValue, ValuePerCellAdjustGrade.Instance.GetStepOfGrade(this.valuePerCellGrade)))
                    {
                        this.baseLineValue -= ValuePerCellAdjustGrade.Instance.GetStepOfGrade(this.valuePerCellGrade);
                    }
                    else
                    {
                        this.baseLineValue = InternalUtils.GetIntegralMultipleOfStepBaseValueOf(this.baseLineValue, ValuePerCellAdjustGrade.Instance.GetStepOfGrade(this.valuePerCellGrade), false);
                    }
                }
                else if (InternalUtils.IsXbeDivByYwithNoRemainder(this.baseLineValue, ValuePerCellAdjustGrade.Instance.GetStepOfGrade(this.valuePerCellGrade)))
                {
                    this.baseLineValue -= ValuePerCellAdjustGrade.Instance.GetStepOfGrade(this.valuePerCellGrade);
                }
                else
                {
                    this.baseLineValue = 0.0 - InternalUtils.GetIntegralMultipleOfStepBaseValueOf(Math.Abs(this.baseLineValue), ValuePerCellAdjustGrade.Instance.GetStepOfGrade(this.valuePerCellGrade), true);
                }
            }
        }

        // Token: 0x0600007F RID: 127 RVA: 0x0000571A File Offset: 0x0000391A
        public void RefreshChannelBuffer()
        {
            if (this.curveGenerator != null)
            {
                this.curveGenerator.Dispose();
            }
            this.curveGenerator = CurveGeneratorFactory.CurveGenerator(this);
        }

        // Token: 0x06000080 RID: 128 RVA: 0x0000573B File Offset: 0x0000393B
        public IChannelBuffer GetChannelBuffer()
        {
            return this.oscs.GetChannelBufferManager().GetChannelBuffer(this.channelSN);
        }

        // Token: 0x06000081 RID: 129 RVA: 0x00005753 File Offset: 0x00003953
        public void SetColor(Color color)
        {
            this.lineColor = color;
        }

        // Token: 0x06000082 RID: 130 RVA: 0x0000575C File Offset: 0x0000395C
        public Color GetColor()
        {
            return this.lineColor;
        }

        // Token: 0x06000083 RID: 131 RVA: 0x00005764 File Offset: 0x00003964
        public void SetLineWidth(float lineWidth)
        {
            if (lineWidth <= 0f)
            {
                throw new ArgumentOutOfRangeException();
            }
            this.lineWidth = lineWidth;
        }

        // Token: 0x06000084 RID: 132 RVA: 0x0000577B File Offset: 0x0000397B
        public void SetBitMask(ushort bitMask)
        {
            this.bitMask = bitMask;
        }
        public void SetOffset(double Offset)
        {
            this.Offset = 0;
            this.Offset = Offset;
        }
        public double GetOffset()
        {
            //return this.Offset;
            this.Offset = 0;
            return this.Offset;

        }
        // Token: 0x06000085 RID: 133 RVA: 0x00005784 File Offset: 0x00003984
        public ushort GetBitMask()
        {
            return this.bitMask;
        }

        // Token: 0x06000086 RID: 134 RVA: 0x0000578C File Offset: 0x0000398C
        public void PrepareDataOfCurve()
        {
            int dataCount = this.oscs.GetChannelBufferManager().GetChannelBuffer(this.channelSN).GetDataCount(this.startTime, this.endTime);
            if (dataCount <= 0)
            {
                this.dataBufferValidCount = 0;
                return;
            }

            this.EnsureDataBufferCapcity(dataCount);
       
            this.dataBufferValidCount = this.oscs.GetChannelBufferManager().GetChannelBuffer(this.channelSN).GetData(this.startTime, this.endTime, this.dataBuffer, 0, ref this.dataBufferStartTime);
            
            this.PreviousDataCount(this.dataBufferValidCount);

        }

        // Token: 0x06000086 RID: 134 RVA: 0x0000578C File Offset: 0x0000398C
        public void PrepareCobvertDataOfCurve(string datatype, double Scal)
        {
            if (datatype == "U32")
            {
                if (dataBuffer != null)
                {
                    for (global::System.Int32 i = 0; i < dataBuffer.Length; i++)
                    {
                        var item = dataBuffer[i];
                        item.Data = item.Data / (double)Scal;
                    }
                }
            }
        }

        // Token: 0x06000087 RID: 135 RVA: 0x0000581A File Offset: 0x00003A1A
        public void PreparePointOfCurve()
        {
            this.curveGenerator.PrepareCurve(this.dataBuffer, this.dataBufferValidCount, this.dataBufferStartTime);

        }

        // Token: 0x06000088 RID: 136 RVA: 0x0000583C File Offset: 0x00003A3C
        public bool GetDataFromChannelBuffer(double mouseMoment, Point mousePoint, ref double data, ref bool isInterpolation)
        {
            if (this.dataBuffer == null)
            {
                return false;
            }
            if (this.oscs.GetChannelBufferManager().GetChannelBuffer(this.channelSN).GetSignalType() == SignalType.DigitalSingle || this.oscs.GetChannelBufferManager().GetChannelBuffer(this.channelSN).GetSignalType() == SignalType.DigitalMultiple)
            {
                return false;
            }
            double timeInterval = this.oscs.GetChannelBufferManager().GetChannelBuffer(this.channelSN).GetTimeInterval();
            double num = mouseMoment - this.dataBufferStartTime;
            int num2 = Convert.ToInt32(Math.Floor(num / timeInterval));
            if (num2 >= this.dataBufferValidCount || num2 < 0)
            {
                return false;
            }
            bool flag = false;
            bool flag2 = false;
            double num3 = 0.0;
            double num4 = 0.0;
            double num5 = 0.0;
            double num6 = 0.0;
            float num7 = 0f;
            float num8 = 0f;
            float num9 = 0f;
            float num10 = 0f;
            double num11 = ValuePerCellAdjustGrade.Instance.GetValueOfGrade(this.valuePerCellGrade) * 8.0;
            float num12 = (float)((double)this.canvasSize.Height * (this.oscs.GetChannelBufferManager().GetChannelBuffer(this.channelSN).GetReferenceValue() / num11));
            float num13 = (float)((double)((float)this.canvasSize.Height / 2f) - (double)this.canvasSize.Height * (this.baseLineValue / num11));
            double num14 = TimePerCellAdjustGrade.Instance.GetValueOfGrade(this.timePerCellGrade) * 10.0;
            for (int i = num2; i >= 0; i--)
            {
                if (this.dataBuffer[i].IsValid)
                {
                    flag = true;
                    num3 = this.dataBufferStartTime + (double)i * timeInterval;
                    num5 = this.dataBuffer[i].Data;
                    num7 = (float)((double)this.canvasSize.Width * ((num3 - this.startTime) / num14));
                    num8 = (float)((double)num12 - (double)this.canvasSize.Height * (num5 / num11) + (double)num13);
                    break;
                }
            }
            for (int j = num2 + 1; j < this.dataBufferValidCount; j++)
            {
                if (this.dataBuffer[j].IsValid)
                {
                    flag2 = true;
                    num4 = this.dataBufferStartTime + (double)j * timeInterval;
                    num6 = this.dataBuffer[j].Data;
                    num9 = (float)((double)this.canvasSize.Width * ((num4 - this.startTime) / num14));
                    num10 = (float)((double)num12 - (double)this.canvasSize.Height * (num6 / num11) + (double)num13);
                    break;
                }
            }
            if (flag && flag2)
            {
                if (Math.Abs(mouseMoment - num3) <= Math.Abs(mouseMoment - num4))
                {
                    if (InternalUtils.GetNormalizedRectangle(num7 - 3f, num8 - 3f, num7 + 3f, num8 + 3f).Contains((float)mousePoint.X, (float)mousePoint.Y))
                    {
                        data = num5;
                        isInterpolation = false;
                        return true;
                    }
                }
                else if (InternalUtils.GetNormalizedRectangle(num9 - 3f, num10 - 3f, num9 + 3f, num10 + 3f).Contains((float)mousePoint.X, (float)mousePoint.Y))
                {
                    data = num6;
                    isInterpolation = false;
                    return true;
                }
                double num15;
                if (num3 == num4)
                {
                    num15 = num5;
                }
                else
                {
                    num15 = (mouseMoment - num3) / (num4 - num3) * (num6 - num5) + num5;
                }
                float num16 = (float)((double)this.canvasSize.Width * ((mouseMoment - this.startTime) / num14));
                float num17 = (float)((double)num12 - (double)this.canvasSize.Height * (num15 / num11) + (double)num13);
                if (InternalUtils.GetNormalizedRectangle(num16 - 3f, num17 - 3f, num16 + 3f, num17 + 3f).Contains((float)mousePoint.X, (float)mousePoint.Y))
                {
                    data = num15;
                    isInterpolation = true;
                    return true;
                }
            }
            else if (flag)
            {
                if (InternalUtils.GetNormalizedRectangle(num7 - 3f, num8 - 3f, num7 + 3f, num8 + 3f).Contains((float)mousePoint.X, (float)mousePoint.Y))
                {
                    data = num5;
                    isInterpolation = false;
                    return true;
                }
            }
            else if (flag2 && InternalUtils.GetNormalizedRectangle(num9 - 3f, num10 - 3f, num9 + 3f, num10 + 3f).Contains((float)mousePoint.X, (float)mousePoint.Y))
            {
                data = num6;
                isInterpolation = false;
                return true;
            }
            return false;
        }
        // Token: 0x06000088 RID: 136 RVA: 0x0000583C File Offset: 0x00003A3C
        public bool GetDataFromChannelBuffer2(double mouseMoment, PointF mousePoint, ref double data, ref bool isInterpolation)
        {
            if (this.dataBuffer == null)
            {
                return false;
            }
            if (this.oscs.GetChannelBufferManager().GetChannelBuffer(this.channelSN).GetSignalType() == SignalType.DigitalSingle || this.oscs.GetChannelBufferManager().GetChannelBuffer(this.channelSN).GetSignalType() == SignalType.DigitalMultiple)
            {
                return false;
            }
            double timeInterval = this.oscs.GetChannelBufferManager().GetChannelBuffer(this.channelSN).GetTimeInterval();
            double num = mouseMoment - this.dataBufferStartTime;
            int num2 = Convert.ToInt32(Math.Floor(num / timeInterval));
            if (num2 >= this.dataBufferValidCount || num2 < 0)
            {
                return false;
            }
            bool flag = false;
            bool flag2 = false;
            double num3 = 0.0;
            double num4 = 0.0;
            double num5 = 0.0;
            double num6 = 0.0;
            float num7 = 0f;
            float num8 = 0f;
            float num9 = 0f;
            float num10 = 0f;
            double num11 = ValuePerCellAdjustGrade.Instance.GetValueOfGrade(this.valuePerCellGrade) * 8.0;
            float num12 = (float)((double)this.canvasSize.Height * (this.oscs.GetChannelBufferManager().GetChannelBuffer(this.channelSN).GetReferenceValue() / num11));
            float num13 = (float)((double)((float)this.canvasSize.Height / 2f) - (double)this.canvasSize.Height * (this.baseLineValue / num11));
            double num14 = TimePerCellAdjustGrade.Instance.GetValueOfGrade(this.timePerCellGrade) * 10.0;
            for (int i = num2; i >= 0; i--)
            {
                if (this.dataBuffer[i].IsValid)
                {
                    flag = true;
                    num3 = this.dataBufferStartTime + (double)i * timeInterval;
                    num5 = this.dataBuffer[i].Data;
                    num7 = (float)((double)this.canvasSize.Width * ((num3 - this.startTime) / num14));
                    num8 = (float)((double)num12 - (double)this.canvasSize.Height * (num5 / num11) + (double)num13);
                    break;
                }
            }
            for (int j = num2 + 1; j < this.dataBufferValidCount; j++)
            {
                if (this.dataBuffer[j].IsValid)
                {
                    flag2 = true;
                    num4 = this.dataBufferStartTime + (double)j * timeInterval;
                    num6 = this.dataBuffer[j].Data;
                    num9 = (float)((double)this.canvasSize.Width * ((num4 - this.startTime) / num14));
                    num10 = (float)((double)num12 - (double)this.canvasSize.Height * (num6 / num11) + (double)num13);
                    break;
                }
            }
            if (flag && flag2)
            {
                if (Math.Abs(mouseMoment - num3) <= Math.Abs(mouseMoment - num4))
                {
                    if (InternalUtils.GetNormalizedRectangle(num7 - 3f, num8 - 3f, num7 + 3f, num8 + 3f).Contains((float)mousePoint.X, (float)mousePoint.Y))
                    {
                        data = num5;
                        isInterpolation = false;
                        return true;
                    }
                }
                else if (InternalUtils.GetNormalizedRectangle(num9 - 3f, num10 - 3f, num9 + 3f, num10 + 3f).Contains((float)mousePoint.X, (float)mousePoint.Y))
                {
                    data = num6;
                    isInterpolation = false;
                    return true;
                }
                double num15;
                if (num3 == num4)
                {
                    num15 = num5;
                }
                else
                {
                    num15 = (mouseMoment - num3) / (num4 - num3) * (num6 - num5) + num5;
                }
                float num16 = (float)((double)this.canvasSize.Width * ((mouseMoment - this.startTime) / num14));
                float num17 = (float)((double)num12 - (double)this.canvasSize.Height * (num15 / num11) + (double)num13);
                if (InternalUtils.GetNormalizedRectangle(num16 - 3f, num17 - 3f, num16 + 3f, num17 + 3f).Contains((float)mousePoint.X, (float)mousePoint.Y))
                {
                    data = num15;
                    isInterpolation = true;
                    return true;
                }
            }
            else if (flag)
            {
                if (InternalUtils.GetNormalizedRectangle(num7 - 3f, num8 - 3f, num7 + 3f, num8 + 3f).Contains((float)mousePoint.X, (float)mousePoint.Y))
                {
                    data = num5;
                    isInterpolation = false;
                    return true;
                }
            }
            else if (flag2 && InternalUtils.GetNormalizedRectangle(num9 - 3f, num10 - 3f, num9 + 3f, num10 + 3f).Contains((float)mousePoint.X, (float)mousePoint.Y))
            {
                data = num6;
                isInterpolation = false;
                return true;
            }
            return false;
        }

        // Token: 0x06000089 RID: 137 RVA: 0x00005CC8 File Offset: 0x00003EC8
        protected void EnsureDataBufferCapcity(int capcity)
        {
            if (this.dataBuffer == null)
            {
                this.dataBuffer = new ChannelBufferData[Channel.DATA_BUFFER_INC_STEP];
            }
            int i;
            for (i = this.dataBuffer.Length; i < capcity; i += Channel.DATA_BUFFER_INC_STEP)
            {
            }
            if (i != this.dataBuffer.Length)
            {
                ChannelBufferData[] array = this.dataBuffer;
                this.dataBuffer = new ChannelBufferData[i];
                Array.Copy(array, this.dataBuffer, array.Length);
                this.dataCountLessThanBufferCapcityCount = 0;
            }
        }

        // Token: 0x0600008A RID: 138 RVA: 0x00005D38 File Offset: 0x00003F38
        protected void PreviousDataCount(int previousDataCount)
        {
            if (this.dataBuffer == null)
            {
                return;
            }
            if (this.dataBuffer.Length - Channel.DATA_BUFFER_DEC_STEP > previousDataCount)
            {
                this.dataCountLessThanBufferCapcityCount++;
            }
            if (this.dataCountLessThanBufferCapcityCount >= Channel.BUFFER_SIZE_ADJUST_THRESHOLD)
            {
                ChannelBufferData[] array = this.dataBuffer;
                if (array.Length - Channel.DATA_BUFFER_DEC_STEP >= 0)
                {
                    this.dataBuffer = new ChannelBufferData[array.Length - Channel.DATA_BUFFER_DEC_STEP];
                    Array.Copy(array, this.dataBuffer, array.Length - Channel.DATA_BUFFER_DEC_STEP);
                }
                this.dataCountLessThanBufferCapcityCount = 0;
                GC.Collect();
            }
        }

        public List<double> PreparePointOfGetDatas()
        {
            return this.curveGenerator.doublesSingle;
        }
        public Oscilloscope.Curve.Curve[] GetCurves()
        {
            Oscilloscope.Curve.Curve[] curves = this.curveGenerator.GetCurves();
            return curves;
        }
        public void DrawCurveUse(Graphics g, Oscilloscope.Curve.Curve[] curves)
        {
            if (curves == null || curves.Length == 0)
            {
                return;
            }
            Pen pen = new Pen(this.lineColor, this.lineWidth);
            for (int i = 0; i < curves.Length; i++)
            {
                if (curves[i] != null && curves[i].CurveSegments != null && curves[i].CurveSegmentCount >= 1 && curves[i].CurvePoints != null)
                {
                    for (int j = 0; j < curves[i].CurveSegmentCount; j++)
                    {
                        if (curves[i].CurveSegments[j].PointCount >= 2)
                        {
                            for (int k = 0; k < curves[i].CurveSegments[j].PointCount - 1; k++)
                            {
                                g.DrawLine(pen, curves[i].CurvePoints[curves[i].CurveSegments[j].StartIndex + k], curves[i].CurvePoints[curves[i].CurveSegments[j].StartIndex + k + 1]);
                            }
                        }
                    }
                }
            }
            pen.Dispose();
        }

       

        // Token: 0x04000027 RID: 39
        private static readonly int DATA_BUFFER_INC_STEP = 5000;

        // Token: 0x04000028 RID: 40
        private static readonly int DATA_BUFFER_DEC_STEP = 1000;

        // Token: 0x04000029 RID: 41
        private static readonly int BUFFER_SIZE_ADJUST_THRESHOLD = 10;

        // Token: 0x0400002A RID: 42
        protected double startTime;

        // Token: 0x0400002B RID: 43
        private double endTime;

        // Token: 0x0400002C RID: 44
        protected int timePerCellGrade;

        // Token: 0x0400002D RID: 45
        protected int valuePerCellGrade;

        // Token: 0x0400002E RID: 46
        protected Rectangle canvasSize;

        // Token: 0x0400002F RID: 47
        protected double baseLineValue;

        // Token: 0x04000030 RID: 48
        private Color lineColor;

        // Token: 0x04000031 RID: 49
        private float lineWidth;

        // Token: 0x04000032 RID: 50
        private int channelSN;

        // Token: 0x04000033 RID: 51
        private ushort bitMask;
        private double Offset;

        // Token: 0x04000034 RID: 52
        protected double dataBufferStartTime;

        // Token: 0x04000035 RID: 53
        protected int dataBufferValidCount;

        // Token: 0x04000036 RID: 54
        public ChannelBufferData[] dataBuffer;

        // Token: 0x04000037 RID: 55
        private int dataCountLessThanBufferCapcityCount;

        // Token: 0x04000038 RID: 56
        private ICurveGenerator curveGenerator;

        // Token: 0x04000039 RID: 57
        private IOscilloscopeScreen oscs;
    }
}
